home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / MPW / gzip 1.2.2 / zgrep.mac < prev    next >
Encoding:
Text File  |  1993-07-11  |  1.5 KB  |  91 lines  |  [TEXT/MPS ]

  1. #
  2. # zgrep.mac -- znew for MPW
  3. #
  4. # written by Anthony C. Ard, 1993
  5. #
  6. # this script requires grep, fgrep, or egrep
  7. #
  8. # zgrep -- a wrapper around a grep program that decompresses files as needed
  9. # Adapted from a version sent by Charles Levert <charles@comm.polymtl.ca>
  10.  
  11. set exit 0
  12. set prog `echo {0} | sed 's|.*/||'`
  13.  
  14. if "{prog}" =~ /≈egrep/
  15.     set grep "egrep"
  16. else if "{prog}" =~ /≈fgrep/
  17.     set grep "fgrep"
  18. else
  19.     set grep "grep"
  20. end
  21.  
  22. unset A
  23. set fileno 0
  24. set pat ""
  25.  
  26. for i in {Parameters}
  27.     if "{1}" == "-e" || "{1}" == "-f"
  28.         set opt "{opt} {1}"
  29.         shift 1
  30.         set pat "{1}"
  31.         if "{grep}" == "grep"
  32.             set grep "egrep"
  33.         end
  34.     else if "{1}" =~ /-≈/
  35.         set opt "{opt} {1}"
  36.     else
  37.         if "{pat}" == ""
  38.             set pat "{1}"
  39.         else
  40.             set fileno `evaluate {fileno} + 1`
  41.             set A "{A} {1}"
  42.         end
  43.     end
  44.     shift 1
  45. end
  46.  
  47. if "{pat}" == ""
  48.     echo "grep through gzip files"
  49.     echo "usage: {prog} [grep_options] pattern [files]"
  50.     set exit 0
  51.     exit 1
  52. end
  53.  
  54. set list 0
  55. set silent 0
  56.  
  57. if "{opt}" != ""
  58.     set op `echo "{opt}" | sed -e 's/ //g' -e 's/-//g'`
  59.  
  60.     if "{op}" =~ /≈l≈/
  61.         set list 1
  62.     else if "{op}" =~ /≈h≈/
  63.         set silent 1
  64.     end
  65. end
  66.  
  67. if {fileno} == 0
  68.     gzip -cdfq | {grep} {opt} "{pat}"
  69.     set res {Status}
  70.     set exit 1
  71.     exit {res}
  72. end
  73.  
  74. set res 0
  75.  
  76. for i in {A}
  77.     if {list}
  78.         gzip -cdfq "{i}" | {grep} {opt} "{pat}" >Dev:Null && echo {i}
  79.         set res {Status}
  80.     else if {#} == 1 || {silent} == 1
  81.         gzip -cdfq "{i}" | {grep} {opt} "{pat}"
  82.         set res {Status}
  83.     else
  84.         gzip -cdfq "{i}" | {grep} {opt} "{pat}" | sed "s|^|{i}; |"
  85.         set res {Status}
  86.     end
  87. end
  88.  
  89. set exit 1
  90. exit {res}
  91.